<template>
  <el-upload
    class="upload-demo"
    ref="upload"
    :action="actionUrl"
    :file-list="fileList"
    :auto-upload="false"
    :headers="upload.headers"
    multiple
    accept=".xlsx"
    :on-success="uploadSuccess"
    :on-error="uploadError"
  >
    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
    <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
    <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
  </el-upload>
</template>

<script>
import {getToken} from "@/utils/auth";
export default {
  name : "MyFilesUpload",
  props: ["actionUrl"],
  data() {
    return {
      fileList: [],
      upload:{
        //url: process.env.VUE_APP_BASE_API + "/common/upload",
        headers: { Authorization: "Bearer " + getToken() },
      }

    };
  },
  methods: {
    init() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.upload.clearFiles();
      });
    },
    submitUpload() {
      this.$refs.upload.submit();
    },
    uploadSuccess(response, file, fileList) {
      console.log(response);
      /*if (response.code == "0") {
        this.$refs.upload.clearFiles();
        this.dialogVisible = false;
        this.$emit("fileHandle", response.filePath);
      } else {
        this.$message({
          type: "info",
          message: `${response.msg}`
        });
      }*/
    },
    uploadError(err, file, fileList) {
      this.$modal.error("文件错误");
    }
  }
};
</script>

<style scoped>
</style>
